home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / OscillatorSpecifier.c < prev    next >
Text File  |  1995-01-08  |  11KB  |  364 lines

  1. /* OscillatorSpecifier.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "OscillatorSpecifier.h"
  31. #include "Memory.h"
  32. #include "SampleSelector.h"
  33. #include "Envelope.h"
  34. #include "LFOListSpecifier.h"
  35. #include "EffectSpecList.h"
  36.  
  37.  
  38. struct OscillatorRec
  39.     {
  40.         /* what kind of oscillator is it */
  41.         OscillatorTypes                        OscillatorType;
  42.  
  43.         /* mapping from pitch to sample */
  44.         struct SampleSelectorRec*    SampleIntervalList;
  45.  
  46.         /* list of oscillators that are modulating us and how */
  47.         struct ModulationSpecRec*    ModulatorInputList;
  48.  
  49.         /* this scales our output so that we can be set relative to other oscillators */
  50.         OscillatorNumType                    OutputLoudness;
  51.  
  52.         /* these are used to make our frequency a multiple of the instrument's */
  53.         /* overall frequency */
  54.         OscillatorNumType                    FrequencyAdjustMultiplier;
  55.         long                                            FrequencyAdjustDivisor;
  56.         OscillatorNumType                    FrequencyAdjustAdder;
  57.  
  58.         /* this switch turns on or off our output, so that we can be used only for */
  59.         /* modulation, if desired.  (True = do use, False = don't use) */
  60.         MyBoolean                                    MixInFinalOutput;
  61.  
  62.         /* this envelope determines the total output level with time */
  63.         struct EnvelopeRec*                LoudnessEnvelope;
  64.  
  65.         /* this LFO list modulates the output of the loudness envelope */
  66.         struct LFOListSpecRec*        LoudnessLFOList;
  67.  
  68.         /* this envelope determines the wave table selection index with time.  this is */
  69.         /* only used for wave table synthesis, not for sampling */
  70.         struct EnvelopeRec*                ExcitationEnvelope;
  71.  
  72.         /* this LFO list modulates the output of the excitation envelope.  it is only */
  73.         /* used for wave table synthesis. */
  74.         struct LFOListSpecRec*        ExcitationLFOList;
  75.  
  76.         /* stereo bias -- fixed amount to move this oscillator left or right by */
  77.         OscillatorNumType                    StereoBias;
  78.         /* surround bias -- fixed amount to move this oscillator front or back by */
  79.         OscillatorNumType                    SurroundBias;
  80.  
  81.         /* time displacement -- how much earlier / later to start sample */
  82.         OscillatorNumType                    TimeDisplacement;
  83.  
  84.         /* list of LFO operators on the frequency for this oscillator */
  85.         struct LFOListSpecRec*        FrequencyLFOList;
  86.  
  87.         /* list of effects applied to oscillator */
  88.         EffectSpecListRec*                EffectSpecList;
  89.     };
  90.  
  91.  
  92. /* create a new oscillator structure */
  93. OscillatorRec*                        NewOscillatorSpecifier(void)
  94.     {
  95.         OscillatorRec*                    Osc;
  96.  
  97.         Osc = (OscillatorRec*)AllocPtrCanFail(sizeof(OscillatorRec),"OscillatorRec");
  98.         if (Osc == NIL)
  99.             {
  100.              FailurePoint1:
  101.                 return NIL;
  102.             }
  103.         Osc->OscillatorType = eOscillatorSampled; /* default -- this is kinda ugly */
  104.         Osc->SampleIntervalList = NewSampleSelectorList(0);
  105.         if (Osc->SampleIntervalList == NIL)
  106.             {
  107.              FailurePoint3:
  108.                 ReleasePtr((char*)Osc);
  109.                 goto FailurePoint1;
  110.             }
  111.         Osc->OutputLoudness = 1;
  112.         Osc->FrequencyAdjustMultiplier = 1;
  113.         Osc->FrequencyAdjustDivisor = 1;
  114.         Osc->FrequencyAdjustAdder = 0;
  115.         Osc->MixInFinalOutput = True;
  116.         Osc->LoudnessEnvelope = NewEnvelope();
  117.         if (Osc->LoudnessEnvelope == NIL)
  118.             {
  119.              FailurePoint5:
  120.                 DisposeSampleSelectorList(Osc->SampleIntervalList);
  121.                 goto FailurePoint3;
  122.             }
  123.         Osc->LoudnessLFOList = NewLFOListSpecifier();
  124.         if (Osc->LoudnessLFOList == NIL)
  125.             {
  126.              FailurePoint6:
  127.                 DisposeEnvelope(Osc->LoudnessEnvelope);
  128.                 goto FailurePoint5;
  129.             }
  130.         Osc->ExcitationEnvelope = NewEnvelope();
  131.         if (Osc->ExcitationEnvelope == NIL)
  132.             {
  133.              FailurePoint7:
  134.                 DisposeLFOListSpecifier(Osc->LoudnessLFOList);
  135.                 goto FailurePoint6;
  136.             }
  137.         Osc->ExcitationLFOList = NewLFOListSpecifier();
  138.         if (Osc->ExcitationLFOList == NIL)
  139.             {
  140.              FailurePoint8:
  141.                 DisposeEnvelope(Osc->ExcitationEnvelope);
  142.                 goto FailurePoint7;
  143.             }
  144.         Osc->FrequencyLFOList = NewLFOListSpecifier();
  145.         if (Osc->FrequencyLFOList == NIL)
  146.             {
  147.              FailurePoint9:
  148.                 DisposeLFOListSpecifier(Osc->ExcitationLFOList);
  149.                 goto FailurePoint8;
  150.             }
  151.         Osc->EffectSpecList = NewEffectSpecList();
  152.         if (Osc->EffectSpecList == NIL)
  153.             {
  154.              FailurePoint10:
  155.                 DisposeLFOListSpecifier(Osc->FrequencyLFOList);
  156.                 goto FailurePoint9;
  157.             }
  158.         Osc->StereoBias = 0;
  159.         Osc->TimeDisplacement = 0;
  160.         return Osc;
  161.     }
  162.  
  163.  
  164. /* dispose of an oscillator structure */
  165. void                                            DisposeOscillatorSpecifier(OscillatorRec* Osc)
  166.     {
  167.         CheckPtrExistence(Osc);
  168.         DisposeSampleSelectorList(Osc->SampleIntervalList);
  169.         DisposeEnvelope(Osc->LoudnessEnvelope);
  170.         DisposeLFOListSpecifier(Osc->LoudnessLFOList);
  171.         DisposeEnvelope(Osc->ExcitationEnvelope);
  172.         DisposeLFOListSpecifier(Osc->ExcitationLFOList);
  173.         DisposeLFOListSpecifier(Osc->FrequencyLFOList);
  174.         DisposeEffectSpecList(Osc->EffectSpecList);
  175.         ReleasePtr((char*)Osc);
  176.     }
  177.  
  178.  
  179. /* set the oscillator type */
  180. void                                            OscillatorSetTheType(OscillatorRec* Osc,
  181.                                                         OscillatorTypes WhatKindOfOscillator)
  182.     {
  183.         ERROR((WhatKindOfOscillator != eOscillatorSampled)
  184.             && (WhatKindOfOscillator != eOscillatorWaveTable),PRERR(ForceAbort,
  185.             "NewOscillatorSpecifier:  bad oscillator type number"));
  186.         CheckPtrExistence(Osc);
  187.         Osc->OscillatorType = WhatKindOfOscillator;
  188.     }
  189.  
  190.  
  191. /* find out what kind of oscillator this is */
  192. OscillatorTypes                        OscillatorGetWhatKindItIs(OscillatorRec* Osc)
  193.     {
  194.         CheckPtrExistence(Osc);
  195.         return Osc->OscillatorType;
  196.     }
  197.  
  198.  
  199. /* get the pitch interval --> sample mapping */
  200. struct SampleSelectorRec*    OscillatorGetSampleIntervalList(OscillatorRec* Osc)
  201.     {
  202.         CheckPtrExistence(Osc);
  203.         return Osc->SampleIntervalList;
  204.     }
  205.  
  206.  
  207. /* get the output loudness of the oscillator */
  208. OscillatorNumType                    OscillatorGetOutputLoudness(OscillatorRec* Osc)
  209.     {
  210.         CheckPtrExistence(Osc);
  211.         return Osc->OutputLoudness;
  212.     }
  213.  
  214.  
  215. /* put a new output loudness in for the oscillator */
  216. void                                            PutOscillatorNewOutputLoudness(OscillatorRec* Osc,
  217.                                                         double NewOutputLevel)
  218.     {
  219.         CheckPtrExistence(Osc);
  220.         Osc->OutputLoudness = NewOutputLevel;
  221.     }
  222.  
  223.  
  224. /* get the frequency multiplier factor */
  225. OscillatorNumType                    OscillatorGetFrequencyMultiplier(OscillatorRec* Osc)
  226.     {
  227.         CheckPtrExistence(Osc);
  228.         return Osc->FrequencyAdjustMultiplier;
  229.     }
  230.  
  231.  
  232. /* get the frequency divisor integer */
  233. long                                            OscillatorGetFrequencyDivisor(OscillatorRec* Osc)
  234.     {
  235.         CheckPtrExistence(Osc);
  236.         return Osc->FrequencyAdjustDivisor;
  237.     }
  238.  
  239.  
  240. /* get the frequency adder thing */
  241. OscillatorNumType                    OscillatorGetFrequencyAdder(OscillatorRec* Osc)
  242.     {
  243.         CheckPtrExistence(Osc);
  244.         return Osc->FrequencyAdjustAdder;
  245.     }
  246.  
  247.  
  248. /* change the frequency adjust factors */
  249. void                                            PutOscillatorNewFrequencyFactors(OscillatorRec* Osc,
  250.                                                         double NewMultipler, long NewDivisor)
  251.     {
  252.         CheckPtrExistence(Osc);
  253.         Osc->FrequencyAdjustMultiplier = NewMultipler;
  254.         Osc->FrequencyAdjustDivisor = NewDivisor;
  255.     }
  256.  
  257.  
  258. /* put a new frequency adder value */
  259. void                                            PutOscillatorFrequencyAdder(OscillatorRec* Osc,
  260.                                                         double NewAdder)
  261.     {
  262.         CheckPtrExistence(Osc);
  263.         Osc->FrequencyAdjustAdder = NewAdder;
  264.     }
  265.  
  266.  
  267. /* get the loudness envelope for the oscillator */
  268. struct EnvelopeRec*                OscillatorGetLoudnessEnvelope(OscillatorRec* Osc)
  269.     {
  270.         CheckPtrExistence(Osc);
  271.         return Osc->LoudnessEnvelope;
  272.     }
  273.  
  274.  
  275. /* get the list of LFO oscillators modulating the loudness envelope output */
  276. struct LFOListSpecRec*        OscillatorGetLoudnessLFOList(OscillatorRec* Osc)
  277.     {
  278.         CheckPtrExistence(Osc);
  279.         return Osc->LoudnessLFOList;
  280.     }
  281.  
  282.  
  283. /* get the excitation envelope for the oscillator */
  284. struct EnvelopeRec*                OscillatorGetExcitationEnvelope(OscillatorRec* Osc)
  285.     {
  286.         CheckPtrExistence(Osc);
  287.         return Osc->ExcitationEnvelope;
  288.     }
  289.  
  290.  
  291. /* get the list of LFO oscillators modulating the excitation envelope output */
  292. struct LFOListSpecRec*        OscillatorGetExcitationLFOList(OscillatorRec* Osc)
  293.     {
  294.         CheckPtrExistence(Osc);
  295.         return Osc->ExcitationLFOList;
  296.     }
  297.  
  298.  
  299. /* get the stereo bias factor */
  300. OscillatorNumType                    OscillatorGetStereoBias(OscillatorRec* Osc)
  301.     {
  302.         CheckPtrExistence(Osc);
  303.         return Osc->StereoBias;
  304.     }
  305.  
  306.  
  307. /* put a new value for the stereo bias factor */
  308. void                                            OscillatorPutStereoBias(OscillatorRec* Osc,
  309.                                                         OscillatorNumType NewStereoBias)
  310.     {
  311.         CheckPtrExistence(Osc);
  312.         Osc->StereoBias = NewStereoBias;
  313.     }
  314.  
  315.  
  316. /* get the surround bias factor */
  317. OscillatorNumType                    OscillatorGetSurroundBias(OscillatorRec* Osc)
  318.     {
  319.         CheckPtrExistence(Osc);
  320.         return Osc->SurroundBias;
  321.     }
  322.  
  323.  
  324. /* put a new value for the surround bias factor */
  325. void                                            OscillatorPutSurroundBias(OscillatorRec* Osc,
  326.                                                         OscillatorNumType NewSurroundBias)
  327.     {
  328.         CheckPtrExistence(Osc);
  329.         Osc->SurroundBias = NewSurroundBias;
  330.     }
  331.  
  332.  
  333. /* get the time displacement factor */
  334. OscillatorNumType                    OscillatorGetTimeDisplacement(OscillatorRec* Osc)
  335.     {
  336.         CheckPtrExistence(Osc);
  337.         return Osc->TimeDisplacement;
  338.     }
  339.  
  340.  
  341. /* put a new value for the time displacement factor */
  342. void                                            OscillatorPutTimeDisplacement(OscillatorRec* Osc,
  343.                                                         OscillatorNumType NewTimeDisplacement)
  344.     {
  345.         CheckPtrExistence(Osc);
  346.         Osc->TimeDisplacement = NewTimeDisplacement;
  347.     }
  348.  
  349.  
  350. /* get the oscillator's frequency LFO list */
  351. struct LFOListSpecRec*        GetOscillatorFrequencyLFOList(OscillatorRec* Osc)
  352.     {
  353.         CheckPtrExistence(Osc);
  354.         return Osc->FrequencyLFOList;
  355.     }
  356.  
  357.  
  358. /* get the effect list for the oscillator */
  359. struct EffectSpecListRec*    GetOscillatorEffectList(OscillatorRec* Osc)
  360.     {
  361.         CheckPtrExistence(Osc);
  362.         return Osc->EffectSpecList;
  363.     }
  364.